﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CycleTimeReport.CApCTRToggleCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Olp.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.CycleTimeReport;

public class CApCTRToggleCmd : TxToggleButtonCommand
{
  private CApCTRMgr m_modeMgr;
  private bool m_pressed;
  private CApCTRToggleEnabler m_enabler;

  public CApCTRToggleCmd()
  {
    this.m_modeMgr = new CApCTRMgr(this);
    this.m_pressed = false;
    this.m_enabler = new CApCTRToggleEnabler();
    CApCTRUtilities.InitRegistryManager((ITxCommand) this);
  }

  public bool Pressed
  {
    get => this.m_pressed;
    set
    {
      this.m_pressed = value;
      this.m_modeMgr.ActivateCycleTimeReport(this.m_pressed);
    }
  }

  public virtual void Execute(object cmdParams)
  {
    try
    {
      this.ToggleState();
      if (!this.Pressed)
        return;
      bool? nullable1 = new bool?(CApCTRUtilities.GetBoolValueFromRegistry("Ignore timer priority", false));
      if (nullable1.HasValue)
        this.IgnoreTimerPriority(nullable1.Value);
      bool? nullable2 = new bool?(CApCTRUtilities.GetBoolValueFromRegistry("Ignore user timers", false));
      if (nullable2.HasValue)
        this.IgnoreUserTimers(nullable2.Value);
      this.ClearTimerSettings();
      List<CApCTRSettingsTimerInfo> settingsTimerInfoList = new List<CApCTRSettingsTimerInfo>();
      foreach (CApCTRSettingsTimerInfo internalTimerSetting in CApCTRUtilities.LoadInternalTimerSettings())
        CApCTRUtilities.AddSettingsTimerInfoToEventsManager(internalTimerSetting);
    }
    catch (Exception ex)
    {
    }
  }

  public virtual bool Licensed => TxCommandLicenser.CycleTimeReportLicense;

  public virtual bool Connect() => true;

  public virtual void Disconnect()
  {
  }

  public virtual string Category => CApCTRStringTable.CATEGORY;

  public virtual string Description => CApCTRStringTable.DESCRIPTION;

  public virtual string Tooltip => CApCTRStringTable.TOOLTIP;

  public virtual string Name => CApCTRStringTable.NAME;

  public virtual string Bitmap => CApCTRStringTable.BITMAP;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("CycleTimeReport");

  public virtual bool Push => this.Pressed;

  public void ToggleState() => this.Pressed = !this.Pressed;

  public bool IsEmptyReport() => this.m_modeMgr.IsEmptyCycleTimeReport();

  public void ClearSimulationData() => this.m_modeMgr.ClearSimulationData();

  public void ClearTimerSettings() => this.m_modeMgr.ClearTimerSettings();

  public void AddTimerSetting(string originalTimerName, TxOlpCTRSettingsTimerInfo setting)
  {
    this.m_modeMgr.AddTimerSetting(originalTimerName, setting);
  }

  public void AutoTestRun(bool value, string reportPath = null)
  {
    this.m_modeMgr.AutoTestRun = value;
    if (reportPath == null)
      return;
    this.m_modeMgr.AutoTestPath = reportPath;
  }

  public CApCTRExcelExporter GetExcelExporter() => this.m_modeMgr.ExcelExporter;

  public bool IsTimerPriorityIgnored() => this.m_modeMgr.IsTimerPriorityIgnored();

  public void IgnoreTimerPriority(bool ignore) => this.m_modeMgr.IgnoreTimerPriority(ignore);

  public bool IsUserTimersIgnored() => this.m_modeMgr.IsUserTimersIgnored();

  public void IgnoreUserTimers(bool ignore) => this.m_modeMgr.IgnoreUserTimers(ignore);

  public bool IsCycleTimeReportActivated() => this.m_modeMgr.IsCycleTimeReportActivated();

  public void ActivateCycleTimeReport(bool activate)
  {
    this.m_modeMgr.ActivateCycleTimeReport(activate);
  }
}
